package net.qunzhi.modules.app.controller;

import java.util.Arrays;
import net.qunzhi.common.utils.BaseQuery;
import net.qunzhi.common.annotation.SysLog;
import net.qunzhi.modules.app.annotation.Login;
import net.qunzhi.modules.app.query.AlarmRecordQuery;
import net.qunzhi.modules.app.utils.JwtUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import net.qunzhi.modules.app.entity.AppTbAlarmRecordConfirmEntity;
import net.qunzhi.modules.app.service.AppTbAlarmRecordConfirmService;
import net.qunzhi.common.utils.PageUtils;
import net.qunzhi.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;


/**
 * 监控报警记录确认表
 *
 * @author zjr
 * @date 2021-11-12 10:36:44
 */
@Api(tags = "app监控报警记录确认表相关")
@RestController
@RequestMapping("app/appTbAlarmRecordConfirm")
public class AppTbAlarmRecordConfirmController {
    @Autowired
    private AppTbAlarmRecordConfirmService appTbAlarmRecordConfirmService;
    @Autowired
    private JwtUtils jwtUtils;

    /**
     * 列表
     */
    @Login
    @ApiOperation("未确认列表")
    @GetMapping("/list")
    public R list(AlarmRecordQuery query, HttpServletRequest request){
        PageUtils page = appTbAlarmRecordConfirmService.queryPage(query, Long.parseLong(jwtUtils.getClaimByToken(request.getHeader(jwtUtils.getHeader())).getSubject()));

        return R.ok().put("page", page);
    }



    @ApiOperation("确认报警信息")
    @PostMapping("/confirm")
    @Login
    public R confirm(@RequestBody AppTbAlarmRecordConfirmEntity form, HttpServletRequest request){
        long userId = Long.parseLong(jwtUtils.getClaimByToken(request.getHeader(jwtUtils.getHeader())).getSubject());
        appTbAlarmRecordConfirmService.confirm(form, userId);

        return R.ok();
    }
}
